<?php
namespace mvc\web;

class View 
{
    public $viewPath;
    public $context;

    public function render($file, $var)
    {
        extract($var);
        $name = get_class($this->context);
        $fullPath =
            $this->viewPath .
            substr(lcfirst(substr($name, strripos($name,'\\')+1)), 0, -10) . "/{$file}.php";

        $layout = $this->viewPath . 'layouts/' . $this->context->layout . '.php';

        ob_start();
        require_once $fullPath;
        $content = ob_get_contents();
        ob_end_clean();
        require_once $layout;
    }
}
